const {
    arrayToMap
} = rx
const app = new BasicTableVue({
    data() {
        return {
            api: tlogActiveApi,
            columns: [
                new TableColumn({width: 30, type: 'selection'}),
                new TableColumn({prop: 'loginName', title: '用户名'}),
                new TableColumn({prop: 'sysUserRoleList', title: '用户类型', customComponent: true}),
                new TableColumn({prop: 'loginSource', title: '来源IP'}),
                new TableColumn({prop: 'createTime', title: '创建时间', formatter: TableColumn.datetimeFormat}),
                new TableColumn({prop: 'lastLoginTime', title: '上次登录时间', formatter: TableColumn.datetimeFormat}),
                new TableColumn({
                    prop: 'status', title: '状态',
                    formatter: () => '活动',
                }),
                new TableColumn({prop: 'operating', title: '操作', customComponent: true}),
            ],
            sysRoleList: [],
            sysRoleMap: new Map(),
        }
    },
    methods: {
        createForm() {
            return new TlogActive({
                userType: '',
            })
        },
        async loginOutSession({id}) {
            const res = await rxPrompt.confirm('你确认要终止此登录会话吗?？', ['确认', '取消'])
            if (!res) {
                return
            }
            if (await ajaxOption({
                res: this.api.logoutSession(id),
                danger: '操作失败',
                success: '操作成功',
            })) {
                await this.searchPage()
            }
        },
        async sysRoleListInit() {
            this.sysRoleList = await sysRoleApi.listForAll()
            this.sysRoleMap = arrayToMap(this.sysRoleList, ({id}) => id, ({name}) => name)
        },
        init() {
            this.sysRoleListInit()
        },
    },
    computed: {
        fieldFormatter() {
            return fieldFormatter
        },
    },
})
